#!/bin/sh
#
# This script is used to test multiple devices grouped in
# the director configuration
#
#
TestName="multi-drive-group-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-2disk-confs
scripts/prepare-disk-changer

echo "s/signature=MD5/signature=MD5; readfifo=yes/" > $tmp/1
echo "s/FileStorage/FileStorage; Device=FileStorage2; Device=FileStorage3; Device=FileStorage4/" >> $tmp/1
sed -f $tmp/1 $conf/susan-dir.conf > $tmp/2
# Allow auto label
$bperl -e 'add_attribute("$tmp/2", "Label Format", "Vol", "Pool", "Default")'
$bperl -e 'add_attribute("$tmp/2", "Label Format", "Vol", "Pool", "Inc")'
$bperl -e 'add_attribute("$conf/susan-sd.conf", "Label Media", "yes", "Device")'

# set this to do round robbin
$bperl -e 'set_maximum_concurrent_jobs("$conf/susan-sd.conf", 1, "Device")'

# Disable spooling for each job
$bperl -e 'add_attribute("$tmp/2", "SpoolData",    "no",  "Job")'
cp $tmp/2 $conf/susan-dir.conf

$bperl -e 'extract_resource("$conf/susan-sd.conf", "Device", "FileStorage")' > $tmp/2
for i in 2 3 4; do
    sed "s/FileStorage/FileStorage$i/" $tmp/2 >> $conf/susan-sd.conf
done

disable_plugins


# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


echo "$tmp/fifo" >>${cwd}/tmp/file-list

mkfifo $tmp/fifo
(sleep 15 > $tmp/fifo)&

change_jobname $JobName
start_test

# test with autolabel
#
#
# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@out /dev/null
messages
@$out ${cwd}/tmp/log1.out
run level=full job=backup storage=File pool=Default yes
run level=full job=backup storage=File pool=Default yes
run level=full job=backup storage=File pool=Default yes
run level=full job=backup storage=File pool=Inc yes
run level=full job=backup storage=File pool=Inc yes
@sleep 3
messages
status storage=File
status dir
messages
wait
messages
quit
END_OF_DATA

run_susan

check_for_zombie_jobs storage=File
check_for_zombie_jobs storage=tape
stop_susan

touch $tmp/log2.out
check_two_logs
#check_restore_diff

end_test
